package juc;

import java.util.concurrent.CountDownLatch;

public class LatchDemo2
{
    static int i = 10;
    public static void main(String[] args)
    {
        final CountDownLatch countDownLatch = new CountDownLatch(5);
        for (int j = 0; j < 5; j++)
        {
            new Thread(() ->
            {
                synchronized (LatchDemo.class)
                {
                    try
                    {
                        System.out.println(Thread.currentThread().getName() + "这是：" + i);
                        i--;
                    }
                    finally
                    {
                        countDownLatch.countDown();
                    }
                }
            },String.valueOf(j)).start();
        }
        try
        {
            countDownLatch.await();
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }
        System.out.println("这是主线程");
    }
}
